#include<bits/stdc++.h>
#define ll long long
const int N=100007;
ll d[N],v[N],a[N];
ll p[N],LL[N],pp[N];

using namespace std;
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
int t;
scanf("%d",&t);
while(t--){
    int n,m,L,V,ol=0;
    scanf("%d%d%d%d",&n,&m,&L,&V);
    memset(LL,0,sizeof(LL));
    for(int i=1;i<=n;i++){
        scanf("%lld%lld%lld",&d[i],&v[i],&a[i]);
        if(a[i]==0){
            if(v[i]>V)ol++;
            while(d[i]<=L){
                LL[d[i]]++;
                pp[i]=LL[d[i]];
                d[i]++;
            }
        }
/*      else if(a[i]>0){}
        else if(a[i]<0){}*/
    }

    sort(LL+1,LL+L+1);
    int ii=L;
    while(LL[ii]==0)ii--;
    int maxnum=LL[ii];
    int ans2=0;
    for(int i=1;i<=m;i++){
        cin>>p[i];
        if(LL[p[i]]==maxnum)ans2++;

    }
    cout<<ol<<" "<<m-ans2<<endl;
}
    return 0;
}
//only for spec.A for 20pts
